<template>
  <div class="action-sheet" v-if="show" @click="cancel">
    <div class="box" :class="box_class">

      <div class="top">
        <dl
          v-for="(item,index) in options"
          :key="value"
          @click="$emit('select',index)"
        >
          <dt><img :src="'/static/action-sheet/'+item.value+'.jpg'" /></dt>
          <dd>{{item.text}}</dd>
        </dl>
      </div>

      <div class="bottom" @click="cancel">取消</div>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        box_class: 'hide'
      }
    },
    props: {
      options: {
        type: Array
      },
      show: {
        type: Boolean,
        default: false
      }
    },
    watch: {
      show (value) {
        setTimeout(() => {
          if (value) {
            this.box_class = 'show'
          } else {
            this.box_class = 'hide'
          }
        }, 100)
      }
    },
    methods: {
      cancel () {
        this.box_class = 'hide'
        setTimeout(() => {
          this.$emit('cancel')
        }, 100)
      }
    }
  }
</script>

<style scoped lang="less">
  @import "../../common/style/var.less";
  .action-sheet{
    position: fixed;
    z-index: 11;
    width: 100%;
    height: 100%;
    top:0;
    left:0;
    background: rgba(0,0,0,.5);
    font-size: @font-size-normal;
  }
  .box{
    position: absolute;
    bottom: 0;
    left:0;
    width: 100%;
    min-height: 150px;
    background: #f2f2f2;
    border-radius: 15px 15px 0 0;
    transition: .3s;
    &.hide{
      transform: translateY(100%);
    }
    &.show{
      transform: translateY(0);
    }
    .top{
      width: 100%;
      min-height: 95px;
      background: #fff;
      margin-bottom: 5px;
      border-radius: 15px 15px 0 0;
      padding:5px 10px 15px 10px;
      box-sizing: border-box;
      overflow: hidden;
      color: @font-assist-a;
      dl{
        float: left;
        width: 60px;
        margin:10px 38px 0 0;
        &:nth-of-type(4n){
          margin-right: 0;
        }
        dt{
          width: 50px;
          height: 50px;
          margin: 0 auto;
          img{
            width: 100%;
            height: 100%;
            border-radius: 25px;
          }
        }
        dd{
          width: 60px;
          height: 20px;
          line-height: 20px;
          text-align: center;
        }
      }
    }
    .bottom{
      width: 100%;
      height: 50px;
      line-height: 50px;
      background: #fff;
      text-align: center;
    }
  }
</style>
